<?php
class Ddup_Reviews_Block_List extends Mage_Catalog_Block_Product_List {
	protected $_reviewsCollection;
	
	protected $_itemLimit = 10;

	protected function _prepareLayout()
    {
        parent::_prepareLayout();

        if ($toolbar = $this->getLayout()->getBlock('reviews_list_index.toolbar')) {
            $toolbar->setCollection($this->getReviewsCollection());
            $this->setChild('reviews.toolbar', $toolbar);
        }

        return $this;
    }
	
	protected function _beforeToHtml()
    {
        $this->getReviewsCollection()
            ->load()
            ->addRateVotes();
        return parent::_beforeToHtml();
    }

	public function getReviewsCollection()
    {
        if (null === $this->_reviewsCollection) {
            $this->_reviewsCollection = Mage::getModel('review/review')->getCollection()
                ->addStoreFilter(Mage::app()->getStore()->getId())
                ->addStatusFilter('approved')
				->setPageSize($this->_itemLimit)
                ->setDateOrder();
        }
        return $this->_reviewsCollection;
    }
	
	public function setItemLimit($limit){		
        if (intval($limit) > 0) {
            $this->_itemLimit = intval($limit);
        }
        return $this;
    }
	
	public function getProduct($productId){
		$product = Mage::getModel('catalog/product')->load($productId);
		return $product;
	}
}